package cn.hzking.gjmall.utils.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.hzking.gjmall.R;

/**
 * Created by Administrator on 2018/3/5.
 */

public class DialogUtils {

    /**
     * 有返回和确定按钮的对话框
     * @param context
     * @param loadingMsg
     * @param isCancelable
     * @return
     */
    public static Dialog createLoadingDialog(Context context, String loadingMsg, boolean isCancelable) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.loading_layout, null);// 得到加载view
        LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);// 加载布局
        // main.xml中的ImageView
        ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);
        TextView tipTextView = (TextView) v.findViewById(R.id.tipTextView);// 提示文字
        // 加载动画
        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
                context, R.anim.loading_anim);
        // 使用ImageView显示动画
        spaceshipImage.startAnimation(hyperspaceJumpAnimation);
        tipTextView.setText(loadingMsg);// 设置加载信息

        Dialog customDialog = new Dialog(context, R.style.dialog);// 创建自定义样式dialog
        customDialog.setCanceledOnTouchOutside(false);
        customDialog.setCancelable(isCancelable);
        customDialog.setContentView(layout, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT,
                LinearLayout.LayoutParams.FILL_PARENT));
        return customDialog;
    }


}
